package com.jumi.microservice.controller.usercash.admin;

import com.alibaba.excel.EasyExcel;
import com.jumi.microservice.common.base.BaseController;
import com.jumi.microservice.common.base.dto.ExportExcelCommonResponse;
import com.jumi.microservice.common.base.dto.ResponseResult;
import com.jumi.microservice.common.page.TableDataInfo;
import com.jumi.microservice.dto.usercash.admin.*;
import com.jumi.microservice.service.usercash.admin.AdminCpsUserCashService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;

/**
 * @author Scw
 * @Date 2020-07-23 11:46
 */
@Api(tags = {"后台提现管理相关接口"})
@RestController
@RequestMapping("admin/cps/userCash")
public class AdminCpsUserCashController extends BaseController {
    @Resource
    private AdminCpsUserCashService adminCpsUserCashService;

    @PostMapping("/export/excel")
    @ApiOperation("导出excel")
    public void exportExcel(ExportCpsUserCashRequest request, HttpServletResponse response) throws IOException {
        ExportExcelCommonResponse<ExportCpsUserCashResponse> exportCpsUserCashResponseExportExcelCommonResponse = adminCpsUserCashService.exportExcel(request);
        response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel");
        response.setCharacterEncoding("utf-8");
        response.setHeader("Content-disposition", "attachment;filename="+ exportCpsUserCashResponseExportExcelCommonResponse.getFileName());
        EasyExcel.write(response.getOutputStream(),ExportCpsUserCashResponse.class).sheet("sheet1").doWrite(exportCpsUserCashResponseExportExcelCommonResponse.getData());
    }

    @GetMapping("/userCashList")
    @ApiOperation("提现列表")
    TableDataInfo<CpsUserCashListResponse> userCashList(CpsUserCashListRequest userCashListRequest) {
        return adminCpsUserCashService.userCashList(userCashListRequest);
    }

    @GetMapping("/cpsCashType/dictionary")
    @ApiOperation("提现账户类型对照字典")
    public ResponseResult<Map<Integer, String>> getCashType() {
        ResponseResult<Map<Integer, String>> result = new ResponseResult<>();
        result.setData(adminCpsUserCashService.getCashType());
        return result;
    }

    @GetMapping("/status/dictionary")
    @ApiOperation("提现状态对照字典")
    public ResponseResult<Map<Integer, String>> getStatus() {
        ResponseResult<Map<Integer, String>> result = new ResponseResult<>();
        result.setData(adminCpsUserCashService.getStatus());
        return result;
    }

    @GetMapping("/checkStatus/dictionary")
    @ApiOperation("审核状态对照字典")
    public ResponseResult<Map<Integer, String>> getCheckStatus() {
        ResponseResult<Map<Integer, String>> result = new ResponseResult<>();
        result.setData(adminCpsUserCashService.getCheckStatus());
        return result;
    }

    @GetMapping(value = "/checkInfo")
    @ApiOperation("审核信息")
    public ResponseResult<CpsUserCashCheckInfoResponse> checkInfo(CpsUserCashIdRequest userCashIdRequest) {
        ResponseResult<CpsUserCashCheckInfoResponse> result = new ResponseResult<>();
        result.setData(adminCpsUserCashService.checkInfo(userCashIdRequest));
        return result;
    }

    @PostMapping(value = "/checkRefuse")
    @ApiOperation("审核拒绝")
    public ResponseResult<Boolean> checkRefuse(CpsUserCashCheckRefuseRequest userCashCheckRefuseRequest) {
        ResponseResult<Boolean> result = new ResponseResult<>();
        userCashCheckRefuseRequest.setOperatorId(getUid());
        userCashCheckRefuseRequest.setOperatorName(getUserName());
        result.setData(adminCpsUserCashService.checkRefuse(userCashCheckRefuseRequest));
        return result;
    }

    @PostMapping(value = "/checkAgree")
    @ApiOperation("审核同意并打款")
    public ResponseResult<Boolean> checkAgree(CpsUserCashCheckAgreeRequest userCashCheckAgreeRequest) {
        ResponseResult<Boolean> result = new ResponseResult<>();
        userCashCheckAgreeRequest.setOperatorId(getUid());
        userCashCheckAgreeRequest.setOperatorName(getUserName());
        result.setData(adminCpsUserCashService.checkAgree(userCashCheckAgreeRequest));
        return result;
    }

    @PostMapping(value = "/checkAgreeBatch")
    @ApiOperation("批量审核同意并打款")
    public ResponseResult<Boolean> checkAgreeBatch(CpsUserCashCheckAgreeBatchRequest userCashCheckAgreeBatchRequest) {
        ResponseResult<Boolean> result = new ResponseResult<>();
        userCashCheckAgreeBatchRequest.setOperatorId(getUid());
        userCashCheckAgreeBatchRequest.setOperatorName(getUserName());
        result.setData(adminCpsUserCashService.checkAgreeBatch(userCashCheckAgreeBatchRequest));
        return result;
    }

    @PostMapping(value = "/checkAgreeAll")
    @ApiOperation("全部审核同意并打款")
    public ResponseResult<Boolean> checkAgreeAll(CpsUserCashCheckAgreeAllRequest userCashCheckAgreeAllRequest) {
        ResponseResult<Boolean> result = new ResponseResult<>();
        userCashCheckAgreeAllRequest.setOperatorId(getUid());
        userCashCheckAgreeAllRequest.setOperatorName(getUserName());
        result.setData(adminCpsUserCashService.checkAgreeAll(userCashCheckAgreeAllRequest));
        return result;
    }

    @GetMapping(value = "/yzh/orderQuery")
    @ApiOperation("云账户-订单查询")
    public ResponseResult<String> orderQuery(OrderQueryRequest orderQueryRequest) {
        ResponseResult<String> result = new ResponseResult<>();
        result.setData(adminCpsUserCashService.orderQuery(orderQueryRequest));
        return result;
    }
}
